template <class P>
class Tvector{
private:
        int nn;                        
        P *v;
public:
       Tvector();                      
       Tvector(int n);                 //Constructor with assigned size of array
       Tvector(int n,const P & a);     //Constructor initialised by const 
       Tvector(int n,const P *a);      //Constructor initialised by array  
       Tvector & operator=(const Tvector &rhs);      
       P & operator[](const int i);    //i'th element       
       const P & operator[](const int i) const;  //i'th element  
       ~Tvector();                     
};

template <class P>
Tvector<P>::Tvector(): nn(0), v(NULL) {} //using condition + initialisation list 

template <class P>
Tvector<P>::Tvector(int n): nn(n) , v(n>0 ? new P[n] : NULL) {}

template <class P>
Tvector<P>::Tvector(int n , const P & a): nn(n) , v(n>0 ? new P[n] : NULL) {
    for (int i=0;i<n;i++) v[i]=a;
}

template <class P>
Tvector<P>::Tvector(int n ,const  P *a): nn(n) , v(n>0 ? new P[n] : NULL) {
    for (int i=0;i<n;i++) v[i]=*a++;
}

template <class P>
Tvector<P> & Tvector<P> :: operator=(const Tvector &rhs){
//      if vector and rhs were different sizes, vector
//		has been resized to match the size of rhs
    if (this != &rhs)
	{
		if (nn != rhs.nn) {
			if (v != NULL) delete[] (v);
			nn=rhs.nn;
			v= nn>0 ? new P[nn] : NULL;
		}
		for (int i=0; i<nn; i++)
			v[i]=rhs[i];
	}
	return *this;
}

template <class P>
P & Tvector<P>::operator[](const int i){                //subscripting
    return v[i];
}

template <class P>
const P & Tvector<P>::operator[](const int i) const {   //subscripting
      return v[i];
}

template <class P>
Tvector<P>::~Tvector(){
    if (v != NULL) delete[] (v);
}
